package com.ruoyi.web.ydz.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.ydz.mapper.LeaveBoardMapper;
import com.ruoyi.web.ydz.domain.LeaveBoard;
import com.ruoyi.web.ydz.service.ILeaveBoardService;

/**
 * 留言板Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-08
 */
@Service
public class LeaveBoardServiceImpl implements ILeaveBoardService 
{
    @Autowired
    private LeaveBoardMapper leaveBoardMapper;

    /**
     * 查询留言板
     * 
     * @param id 留言板主键
     * @return 留言板
     */
    @Override
    public LeaveBoard selectLeaveBoardById(Long id)
    {
        return leaveBoardMapper.selectLeaveBoardById(id);
    }

    /**
     * 查询留言板列表
     * 
     * @param leaveBoard 留言板
     * @return 留言板
     */
    @Override
    public List<LeaveBoard> selectLeaveBoardList(LeaveBoard leaveBoard)
    {
        return leaveBoardMapper.selectLeaveBoardList(leaveBoard);
    }

    /**
     * 新增留言板
     * 
     * @param leaveBoard 留言板
     * @return 结果
     */
    @Override
    public int insertLeaveBoard(LeaveBoard leaveBoard)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        leaveBoard.setCreateBy(user.getNickName());
        leaveBoard.setCreateName(user.getUserName());
        leaveBoard.setCreateTime(DateUtils.getNowDate());
        return leaveBoardMapper.insertLeaveBoard(leaveBoard);
    }

    /**
     * 修改留言板
     * 
     * @param leaveBoard 留言板
     * @return 结果
     */
    @Override
    public int updateLeaveBoard(LeaveBoard leaveBoard)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        leaveBoard.setUpdateBy(user.getNickName());
        leaveBoard.setUpdateName(user.getUserName());
        leaveBoard.setUpdateTime(DateUtils.getNowDate());
        return leaveBoardMapper.updateLeaveBoard(leaveBoard);
    }

    /**
     * 批量删除留言板
     * 
     * @param ids 需要删除的留言板主键
     * @return 结果
     */
    @Override
    public int deleteLeaveBoardByIds(Long[] ids)
    {
        return leaveBoardMapper.deleteLeaveBoardByIds(ids);
    }

    /**
     * 删除留言板信息
     * 
     * @param id 留言板主键
     * @return 结果
     */
    @Override
    public int deleteLeaveBoardById(Long id)
    {
        return leaveBoardMapper.deleteLeaveBoardById(id);
    }
}
